package com.sports.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sports.demo.basic.BasicController;
import com.sports.demo.model.Facilities;
import com.sports.demo.req.NameReq;
import com.sports.demo.service.FacilitiesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 设施 前端控制器
 * </p>
 *
 * @author SRG
 * @since 2022-03-13
 */
@RestController
@RequestMapping("/facilities")
public class FacilitiesController extends BasicController<FacilitiesService, Facilities> {


  @PostMapping({"getPage"})
  public IPage<Facilities> page(@RequestBody NameReq req) {
    LambdaQueryWrapper<Facilities> query = Wrappers.lambdaQuery(Facilities.class).orderByDesc(Facilities::getId);
    if (StringUtils.hasText(req.getName())) {
      query.like(Facilities::getFacilitiesName, req.getName());
    }
    IPage<Facilities> page = getBasicService().page(req.getPlusPage(), query);
    return page;
  }

  @PostMapping("venueFacilitiesList")
  @ApiOperation(value="场馆下设施列表", notes="")
  public List<Facilities> venueFacilitiesList(@RequestBody IdReq req) {
    return getBasicService().list(Wrappers.lambdaQuery(Facilities.class).eq(Facilities::getVenueId,req.getId()));
  }

  @PostMapping("scrap")
  @ApiOperation(value="报废", notes="")
  public boolean scrap(@RequestBody Facilities req) {
    Facilities facilities = getBasicService().getById(req.getId());
    facilities.setStat(req.getStat());
    return getBasicService().updateForUniqueKey(facilities);
  }


}
